package com.yonyougov.devops.cruxcisupport.deployhistory;

import com.yonyougov.devops.cruxcisupport.deployhistory.dto.DeployHisPageLikeDto;
import com.yonyougov.devops.cruxcisupport.deployhistory.vo.DeployHisPageLikeVo;
import com.yonyougov.devops.cruxcisupport.util.CruxDevOpsIdGenerator;
import com.yonyougov.devops.fwc.core.dao.BaseDao;
import com.yonyougov.devops.fwc.core.entity.Pagination;
import com.yonyougov.devops.fwc.core.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * t_deploy_his服务实现
 */
@Service
public class DeployHisServiceImpl extends BaseServiceImpl<DeployHisEntity, BigInteger> implements DeployHisService {
    private final DeployHisDao deployHisDao;

    public DeployHisServiceImpl(DeployHisDao deployHisDao) {
        this.deployHisDao = deployHisDao;
    }

    @Override
    public BaseDao<DeployHisEntity, BigInteger> getDao() {
        return deployHisDao;
    }
    //<!--用户自定义代码开始-->

    /**
     * 部署历史表id生成
     *
     * @return [java.math.BigInteger]
     */
    @Override
    public BigInteger idGenerat() {
        return new CruxDevOpsIdGenerator().generatorId(deployHisDao);
    }

    /**
     * 新增部署历史
     * 类型: 批量
     *
     * @param deployHisEntityList [java.util.List: com.yonyougov.devops.cruxcisupport.deployhistory.DeployHisEntity]
     */
    @Override
    public void batchAddDeployHistory(List<DeployHisEntity> deployHisEntityList) {
        deployHisDao.batchInsert(deployHisEntityList);
    }

    /**
     * 查询部署历史
     * 条件: 环境id, 环境名称, 应用id, 应用名称
     *
     * @param deployHisPageLikeDto [com.yonyougov.devops.cruxcisupport.deployhistory.dto.DeployHisPageLikeDto]
     * @return [com.yonyougov.devops.fwc.core.entity.Pagination]
     */
    public Pagination<DeployHisPageLikeVo> findDeployHisPageLike(DeployHisPageLikeDto deployHisPageLikeDto) {
        List<DeployHisPageLikeVo> list = deployHisDao.findPageBy(deployHisPageLikeDto);
        int totalCount = deployHisDao.countBy(deployHisPageLikeDto);

        return new Pagination<DeployHisPageLikeVo>(deployHisPageLikeDto.getMax(), deployHisPageLikeDto.getPageNum(), totalCount, list);
    }
    //<!--用户自定义代码结束-->
}
